﻿using System;
using System.Collections.Generic;
using Rabbit.Logic;
using RabbitShop.Code;

namespace RabbitShop.UI
{
    public partial class ConfirmOrder : System.Web.UI.Page
    {
        protected string uid = string.Empty;
        protected List<ShopCartViewItem> list;
        //protected List<Address> listAd;
        //protected string cartJson = string.Empty;
        protected CartTotal CartTotal;
        protected int selectedIndex;
        protected decimal diliveryCost;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies[Constant.CookieName] != null)
            {
                string id = Request.Cookies[Constant.CookieName].Values[Constant.CookieUid];
                if (string.IsNullOrEmpty(id))
                {
                    Response.Redirect("UserLogon.aspx");
                    return;
                }
                uid = id;

                Customer customer = RabbitUse.GetCustomerById(Db.Store, uid);
                list = RabbitUse.GetShopCartView(Db.Store, customer);
                myRepeater.DataSource = list;
                myRepeater.DataBind();
                List<Address> addresses = customer.AddressList;
                addressRepeater.DataSource = addresses;
                addressRepeater.DataBind();

                selectedIndex = customer.DefaultAddressIndex;

                Address address = customer.AddressList[selectedIndex];
                //RabbitUse.GetShipRuleByShopId(Db.Store, )

                //cartJson = JsonConvert.SerializeObject(customer.Cart);
                CartTotal = RabbitUse.ComputeCartTotal(Db.Store, customer.Cart);
            }
            else
            {
                Response.Redirect("UserLogon.aspx");
            }

           
        }
    }
}